#ifndef __INS_DET_H__
#define __INS_DET_H__

#include "stdint.h"

#ifdef __cplusplus
extern "C" {
#endif

#define INS_SP_CHN                  3
#define INS_SN_CHN                  14

#define INS_RV                      500
#define INS_VOL                     4000        /* 单位：0.1/v */
#define INS_CURR                    20000       /* 单位：mA */

#define ENABLE_INS_EVT              (1 << 0u)

#define T_ACQ_DFLT                  1               // Default measurement/acquisition period
#define R_PS_DFLT                   68100.0         // Input series  resistance positive branch
#define R_NS_DFLT                   68100.0         // Input series resistance negative branch
#define R_S_DFLT                    120.0           // Current sense resistor in front of AMC3330
#define V_REF_DFLT                  1.65            // Reference voltage
#define K_ADC_DFLT                  2               // AMC3330 Gain Riso sensing
#define K_BATT_DFLT                 2               // AMC3330 Gain Vbus sensing
#define k_DIFF2SINISO_DFLT          0.825           // Differential to single ended conversion Gain Riso measurement
#define k_DIFF2SINBATT_DFLT         1.65            // Differential to single ended conversion Gain Vbus measurement
#define R_PS_DFLT_DC                990000.0        // Input series resistance
#define R_S_DFLT_DC                 2100.0          // Feedback resistance
#define V_REF_DFLT_DC               0.0             // Common Mode Reference for Dif2Sing conversion Bus Monitoring

/* ADC的参考电压 */
#define ADC_REF     3.30f

enum {
    RELAY_POS = 0,
    RELAY_NEG
};

enum {
    INS_IDLE_STATE = 0,
    INS_POS_ON_NEG_OFF_STATE,
    INS_GET_VP_STATE,
    INS_POS_OFF_NEG_ON_STATE,
    INS_GET_VN_STATE,
    INS_GET_RISO_STATE,
    INS_END_STATE
};

int get_ins_state(void);
uint32_t get_dc_bus_voltage(void);
int insulation_detection_fsm(void);
#ifdef __cplusplus
}
#endif

#endif  /* __INS_DET_H__ */


